package org.sxp.common.customDialect;

import org.springframework.context.annotation.Configuration;
import org.thymeleaf.dialect.AbstractProcessorDialect;
import org.thymeleaf.processor.IProcessor;
import org.thymeleaf.standard.StandardDialect;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * Created by klaus on 2018/5/18.
 */
@Configuration
public class DictDialect extends AbstractProcessorDialect {
    private static final String NAME = "Dict";
    private static final String PREFIX = "dict";

    public DictDialect() {
        super(NAME, PREFIX, StandardDialect.PROCESSOR_PRECEDENCE);
    }

    @Override
    public Set<IProcessor> getProcessors(String dialectPrefix) {
        return createStandardProcessorsSet(dialectPrefix);
    }

    private Set<IProcessor> createStandardProcessorsSet(String dialectPrefix) {
        LinkedHashSet<IProcessor> processors = new LinkedHashSet<IProcessor>();
        processors.add(new DictSelectProcessor(dialectPrefix));
        processors.add(new DictTextProcessor(dialectPrefix));
        return processors;
    }
}
